package com.zookeeper;

import org.junit.Test;

//没办法同时启动两个客户端，测试不了
public class MyLockTest {

    private void sell(){
        System.out.println("售票开始");
        try {
            Thread.sleep(2*1000);
        }catch (Exception e){
            e.printStackTrace();
        }
        System.out.println("售票结束");
    }

    public void sellSync(){
        MyLock myLock = new MyLock();
        myLock.acquireLock();
        sell();
        myLock.closeLock();
    }

    @Test
    public void test(){

        new Thread(new Runnable() {
            public void run() {
                MyLockTest myLockTest = new MyLockTest();
                for (int i = 0; i < 10; i++) {
                    System.out.println("客户端2");
                    myLockTest.sellSync();
                }
            }
        }).start();

        MyLockTest myLockTest = new MyLockTest();
        for (int i = 0; i < 10; i++) {
            System.out.println("客户端1");
            myLockTest.sellSync();
        }


    }

}
